﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace XiaoYuStock.Core.Entities
{
    public class PlateDataHelper
    {
        /// <summary>
        /// 上证综合指数
        /// </summary>
        public static string SHPlateUrl = "http://hq.sinajs.cn/list=s_sh000001";


        /// <summary>
        /// 深诚综合指数
        /// </summary>
        public static string SZPlateUrl = "http://hq.sinajs.cn/list=s_sz399001";
        /// <summary>
        /// 转换为数据对象
        /// var hq_str_s_sh000001=\"上证指数,3361.8404,74.1299,2.25,2388866,28524322\";
        /// </summary>
        /// <param name="Content"></param>
        /// <returns></returns>
        public static PlateData ConvertToObj(string Content)
        {

            PlateData transData = new PlateData();
            if (string.IsNullOrWhiteSpace(Content))
                return transData;
            Regex reg_Content = new Regex(@".*?hq_str.*?(\d+)=""(.*?)""", RegexOptions.IgnoreCase);
            if (!reg_Content.IsMatch(Content))
                return transData;
            var m=reg_Content.Match(Content);
            transData.SharesCode = m.Groups[1].Value;
            string[] ArrayData = m.Groups[2].Value.Split(',');
            if (ArrayData == null || ArrayData.Length < 1)
                return transData;
            transData.SharesName = ArrayData[0];
            transData.CurrentPoint = Convert.ToDecimal(ArrayData[1]);
            transData.CurrentPrice = Convert.ToDecimal(ArrayData[2]);
            transData.PreRate = Convert.ToDecimal(ArrayData[3]);
            transData.TradeCount = Convert.ToDecimal(ArrayData[4]);
            transData.TradeAmount = Convert.ToDecimal(ArrayData[5]);
            return transData;
        }
    }
}
